/**
 * Pinganfu.com Inc.
 * Copyright (c) 2003-2013 All Rights Reserved.
 */
package com.huatai.vba.grovvy.base;

import java.util.*;

/**
 * 需要动态加载到Spring中的Bean配置信息
 */
public final class DynamicBean {

	/** 存储属性的map */
	private final Map<String, String> properties = new HashMap<String, String>();

	/**
	 * 添加属性
	 * 
	 * @param key
	 * @param value
	 */
	public void put(String key, String value) {
		properties.put(key, value);
	}

	/**
	 * 遍历属性
	 * 
	 * @return
	 */
	public Iterator<String> keyIterator() {
		return properties.keySet().iterator();
	}

	/**
	 * 返回属性值
	 * 
	 * @param key
	 * @return
	 */
	public String get(String key) {
		return properties.get(key);
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		StringBuilder retValue = new StringBuilder("DynamicBean[");
		retValue.append("properties=").append(this.properties).append(']');
		return retValue.toString();
	}

	public String toXmlString() {
		String idStr = "id=\"" + properties.get("id") + "\"";
		String scriptStr = "script-source=\"" + properties.get("script-source") + "\"";
		return " <" + GroovyConstant.SPRING_TAG + " " + idStr + " " + scriptStr + " />\n";
	}
}
